package main

import (
	"flag"
	"fmt"
	"os/exec"
)

func main() {
	file := flag.String("f", "", "go file")
	st := flag.String("s", "", "struct")
	at := flag.String("at", "", "add tags")
	aj := flag.Bool("aj", false, "add json tags")
	ajo := flag.Bool("ajo", false, "add json tags with omitempty")
	rt := flag.String("rt", "", "remove tags")
	rjo := flag.Bool("rjo", false, "remove json tags omitempty")
	t := flag.String("t", "camelcase", "transform default camelcase")
	w := flag.Bool("w", true, "write to file default true")
	flag.Parse()

	args := make([]string, 0)
	if *file == "" {
		fmt.Println("must set go file, use f")
		return
	}
	args = append(args, "-file", *file)
	if *st == "" {
		fmt.Println("must set struct, use s")
		return
	}
	args = append(args, "-struct", *st)

	switch {
	case *aj:
		args = append(args, "-add-tags", "json")
	case *ajo:
		args = append(args, "-add-tags", "json", "-add-options", "json=omitempty")
	case *at != "":
		args = append(args, "-add-tags", *at)
	case *rjo:
		args = append(args, "-remove-options", "json=omitempty")
	case *rt != "":
		args = append(args, "-remove-tags", *rt)
	}

	if *t != "" {
		args = append(args, "-transform", *t)
	}
	if *w {
		args = append(args, "-w")
	}

	if err := exec.Command("gomodifytags", args...).Run(); err != nil {
		panic(err)
	}
}
